<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 1000px;
            height: 600px;
            background-color: aqua;
            margin: 0 auto;
            position: relative;
            background: url("../FZ传输文件/001.jpg");
            background-size: cover;

        }

        .left,
        .right {
            width: 50px;
            height: 60px;
            background-color: rgba(0, 0, 0, 0.5);
            color: black;
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            font-size: 50px;
            text-align: center;
            line-height: 50px;
        }

        .right {
            right: 0;
        }

        ul {
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
            width: 250px;
            height: 100px;
            /* background-color: gray; */
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        li {
            display: block;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: grey;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
        }

        .active {
            background-color: orange;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="right">&gt;</div>
        <div class="left">&lt;</div>
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
    </div>
    <script>
        let arr = ["url('../FZ传输文件/001.jpg')", "url('../FZ传输文件/002.jpg')", "url('../FZ传输文件/003.jpg')", "url('../FZ传输文件/004.jpg')"]
        let lis = document.querySelectorAll("li")
        let box = document.querySelector(".box")
        let left = document.querySelector(".left")
        let right = document.querySelector(".right")
        let a = 0
        for (let i = 0; i < lis.length; i++) {
            const spans= lis[i]
            lis[i].onclick = function () {
                a = i
                // let active = document.querySelector(".active")
                document.querySelector(".active").className = ""
                box.style.background = arr[i]
                this.classList.add("active")
                // left.onclick()
                // right.onclick()
            }
            // left.onclick = function () {
            //     if (lis[i].innerText == 1) {
            //         lis[3].classList.add("active")
            //         document.querySelector(".active").classList.remove("active")
            //     } else {
            //         document.querySelector(".active").className = ""
            //         active.previousElementSibling.classList.add("active")
            //     }
            // }
            left.onclick = function () {
                // if(i == 3){
                // lis[0].onclick()
                // }else{
                // console.log(i);
                // i--
                // if (i == -1) {
                //     i = 3
                // }
                // lis[i].onclick()

                a--;
                if (a < 0) {
                    lis[3].onclick()
                    a = 3
                }else{
                    lis[a].onclick()
                }

                // }
                // if (lis[i].innerText === 4) {
                //     document.querySelector(".active").classList.remove("active")
                //     lis[0].classList.add("active")
                // } else {
                //     document.querySelector(".active").nextElementSibling.classList.add("active")
                //     document.querySelector(".active").className = ""
                // }
            }
            right.onclick = function () {
                // console.log(i);
                // if (i == 4) {
                //     i = 0
                //     lis[i].onclick()
                // } else {
                //     lis[i].onclick()
                //     i++
                // }
               
                // const active = document.querySelector(".active")
                // active.nextElementSibling.onclick()
                // if(active.nextElementSibling != null){
                //     active.nextElementSibling.onclick()//执行下一个兄弟选择器   .onclick表示  的  点击事件
                // }else{
                //     lis[0].onclick()

                // }

                a++;
                if (a > lis.length - 1) {
                    lis[0].onclick()
                    a = 0
                }else{
                    lis[a].onclick()
                }
            }
        }
            // let box = document.querySelector(".box")
            let timer;
            box.onmouseenter = function(){
                clearInterval(timer)
            }
            box.onmouseleave = function(){
                timer = setInterval(function(){
                    right.onclick()
                },2000)
            }
            
            timer = setInterval(function(){
                    right.onclick()
                },2000)


























    </script>

</body>

</html>